package com.example.win.android_banduyujia.peopleactivity.ui.domain;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.example.win.android_banduyujia.peopleactivity.ui.controller.AlbumController;
import com.example.win.android_banduyujia.peopleactivity.ui.image.PhotoSelectorActivity;
import com.example.win.android_banduyujia.peopleactivity.ui.image.PhotoSelectorActivity.OnLocalAlbumListener;
import com.example.win.android_banduyujia.peopleactivity.ui.image.PhotoSelectorActivity.OnLocalReccentListener;
import com.example.win.android_banduyujia.peopleactivity.ui.model.AlbumModel;
import com.example.win.android_banduyujia.peopleactivity.ui.model.PhotoModel;

import java.util.List;

/**
 * Created by Win on 2015/9/17.
 */
public class PhotoSelectorDomain {

    private AlbumController albumController;

    public PhotoSelectorDomain(Context context) {
         albumController = new AlbumController(context);
    }

    public void getReccent(final OnLocalReccentListener listener) {
         final Handler handler = new Handler(){
            @Override
            public void handleMessage(Message msg) {
             //   listener.onPhotoLoaded((List<PhotoModel>) msg.obj);
            }
        };
        new Thread(new Runnable() {
            @Override
            public void run() {
               List<PhotoModel>  photos = albumController.getCurrent();
                Message  msg = Message.obtain();
                msg.obj = photos;
                handler.sendMessage(msg);
            }
        }).start();
    }

    /** 获取相册列表 */
    public void updateAlbum(final OnLocalAlbumListener listener) {
         final Handler handler = new Handler(){
             @Override
             public void handleMessage(Message msg) {
                 listener.onAlbumLoaded((List<AlbumModel>) msg.obj);
             }
         };
        new Thread(new Runnable() {
            @Override
            public void run() {
                List<AlbumModel> albums = albumController.getAlbums();
                Message  msg = Message.obtain();
                msg.obj = albums;
                handler.sendMessage(msg);
            }
        }).start();
    }

    /** 获取单个相册下的所有照片信息 */
    public void getAlbum(final String name, final OnLocalReccentListener listener) {
         final Handler handler = new Handler(){
             @Override
             public void handleMessage(Message msg) {
                 listener.onPhotoLoaded((List<PhotoModel>) msg.obj);
             }
         };
        new Thread(new Runnable() {
            @Override
            public void run() {
                List<PhotoModel> photos = albumController.getAlbum(name);
                Message msg = Message.obtain();
                msg.obj = photos;
                handler.sendMessage(msg);
            }
        }).start();
    }
}
